import type { FormRules } from 'element-plus'
import { reactive } from 'vue'
import { isTel } from '@/utils/regexp'
export const form = reactive({
  businesstype: '',
  companyname: '',
  companycode: '',
  registration: '',
  contact: '',
  tel: ''
})
const validateorTel = (rule: any, value: any, callback: any) => {
  if (!isTel(value)) {
    callback(new Error('手机号码格式不正确'))
  } else {
    callback()
  }
}
export const rules = reactive<FormRules>({
  'businesstype': [{ required: true, message: '请选择业务类型' }],
  'companyname': [{ required: true, message: '请输入企业名称' }],
  'companycode': [{ required: true, message: '请输入企业编号' }],
  'registration': [{ required: true, message: '请输入企业注册地' }],
  'contact': [{ required: true, message: '请输入企业联系人' }],
  'tel': [
    { required: true, message: '请输入联系人电话', trigger: 'blur' },
    { validator: validateorTel, trigger: 'blur' }
  ],
})
export const saveAdd = (callback?: Function) => {
  typeof callback === 'function' && callback()
}
export const queryEdit = (id: string) => {
  console.log('id:==', id)
} 
export const saveEdit = (callback?: Function) => {
  typeof callback === 'function' && callback()
}
export const saveDel = (id: string, callback?: Function) => {
  console.log('id--:', id)
  typeof callback === 'function' && callback()
}